


type JsonResult = {
    code: number
    msg: string
    data: any
}


export const jsonData = function (code: number, msg: string, data: any): JsonResult {
    return {
        code,
        msg,
        data,
    }
}

export const jsonOK = function (data: any): JsonResult {
    return {
        code: 200,
        msg: "success",
        data,
    }
}


export const jsonFail = function (code: number, msg: string): JsonResult {
    return jsonData(code, msg, null)
}


export const paramErrorJson = function (msg: string): JsonResult {
    return jsonFail(400, msg)
}


export const isNull = (data: any) => {
    return data === null || data === undefined
}

export const isBlank = (data: string) => {
    return isNull(data) || data.trim().length === 0
}

export const isEmpty = (data: any) => {
    return isNull(data) || !Array.isArray(data) || data.length === 0;
}